package com.chixing.ih.module.programmer.controller;

import com.chixing.ih.json.ResponseData;
import com.chixing.ih.module.programmer.pojo.Evaluate;
import com.chixing.ih.module.programmer.pojo.dto.EvaluateDTO;
import com.chixing.ih.module.programmer.service.IEvaluateService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @version 1.0
 * @Author MasterYan
 * @Date 2020/10/4
 * Time: 9:36
 */
@RestController
@RequestMapping("/evaluation")
@Api(tags = "程序员模块评价相关Api")
public class EvaluateController {

    @Autowired
    IEvaluateService evaluateService;


    /**
     * desc:查询评价接口
     *
     * @param userEvaluatedId
     * @return
     */
    @ApiOperation(value = "查询评价接口", notes = "查询程序员所有评价")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userEvaluatedId", value = "被评价人id", required = true, dataType = "long"),

    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 400, message = "查询失败")
    })
    @GetMapping("/evaluation/{userEvaluatedId}")
    public Map<String, Object> listEvaluations(@PathVariable("userEvaluatedId") long userEvaluatedId) {
        List<EvaluateDTO> evaluateDTOS = evaluateService.listAll(userEvaluatedId);
        return ResponseData.REP_GET_SUCCESS(evaluateDTOS);

    }

    /**
     * desc:保存评价接口
     *
     * @param evaluate
     * @return
     */
    @ApiOperation(value = "保存评价接口", notes = "批量保存评价")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userEvaluateId", value = "评价人id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "userEvaluatedId", value = "被评价人id", required = true,dataType = "long"),
            @ApiImplicitParam(name = "skillScore", value = "技能评价分数", dataType = "int"),
            @ApiImplicitParam(name = "attitudeScore", value = "态度评价分数", dataType = "int"),
            @ApiImplicitParam(name = "punctualityScore", value = "及时度评价分数", dataType = "int"),
            @ApiImplicitParam(name = "evaluatedDesc", value = "评价描述", dataType = "string"),
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "long")
    })
    @ApiResponses({
            @ApiResponse(code = 201, message = "保存成功"),
            @ApiResponse(code = 400, message = "保存失败")
    })

    @PostMapping("/evaluation")
    public Map<String, Object> saveEvaluate(@RequestBody Evaluate evaluate) {
        boolean flag = evaluateService.insertOne(evaluate);
        if (flag)
            return ResponseData.REP_CREATED_SUCCESS();
        else
            return ResponseData.REP_INVALID_ERROR();

    }


}
